<?php
/**
 * Created by PhpStorm.
 * User: Yui
 * Date: 2017/5/10 0010
 * Time: 14:19
 */

namespace backend\controllers;

use Yii;
use common\controllers\BackendCommonCtrl;
use common\services\UserSve;

class UserController extends BackendCommonCtrl
{
    public function actionEdit()
    {
        $request = Yii::$app->request;
        $id = Yii::$app->getUser()->getId();
        $UserSve = new UserSve();
        if ($request->isPost) {
            $post = $request->post();
            $post['id'] = $id;
            $rs = $UserSve->update($post);
            return $this->asJson($rs);
        } else {
            $rs = $UserSve->getInfo(['id' => $id]);
            if ($rs['code'] !== 0) {
                #TODO 404
            }
            return $this->render('edit', ['User' => $rs['data']['Obj']]);
        }
    }
}